package com.xlhj.task.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @Author: lcj
 * @Date: 2020/11/26 9:37
 * @Description: TODO
 * @Version: 0.0.1
 */
@Slf4j
@Component
public class ScheduledService {

    @Async("schedulePoolTaskExecutor")
    @Scheduled(cron = "0/5 * * * * *")
    public void scheduled() {
        log.info("======使用cron{}", System.currentTimeMillis());
    }

    /**
     * 启动后10秒开始执行，固定5秒周期执行一次
     */
    @Async("schedulePoolTaskExecutor")
    @Scheduled(initialDelay = 10000, fixedRate = 5000)
    public void scheduled1() {
        log.info("======使用fixedRate{}", System.currentTimeMillis());
    }

    /**
     * 启动后10秒开始执行，距离上次执行结束之后20秒再执行下一次
     */
    @Async("schedulePoolTaskExecutor")
    @Scheduled(initialDelay = 10000, fixedDelay = 5000)
    public void scheduled2() {
        log.info("======使用fixedDelay{}", System.currentTimeMillis());
    }
}
